--- 战策五·声东击西
local policy5 = fk.CreateSkill {
    name = "trueaim_another",
    tags = { Skill.Compulsory },
    dynamic_name = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
    dynamic_desc = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
}

local HG = require "packages.new_heg_diy_my.util"

Fk:loadTranslationTable{
    ["@[trueaim_another_mark]"] = "声东击西",
    ["trueaim_another_ask"] = "战策-声东击西：你可以重新指定一名其他角色为此牌的目标",
}

policy5:addEffect(fk.AfterCardTargetDeclared, {
    can_trigger = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy5.name .. "_mark"
        return player:getMark(mark_name) ~= 0 and data.from == player and #data.tos == 1
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local chooses = room:getOtherPlayers(player)
        local tos = room:askToChoosePlayers(player, {
            targets = chooses,
            min_num = 1,
            max_num = 1,
            prompt = "trueaim_another_ask",
            skill_name = "unknownpolicy",
            cancelable = true,
        })
        if #tos ~= 0 then
            event:setCostData(self, { tos = tos })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local mark_name = "@[private]" .. policy5.name .. "_mark"
        data.tos = {}
        local to = event:getCostData(self).tos
        for i = 1, #to, 1 do
            data:addTarget(to[i])
        end
        room:setPlayerMark(player, mark_name, 0)
        room:handleAddLoseSkills(player, "-trueaim_another", nil, false)
        room.logic:trigger(HG.HegLosePolicy, player, { player, policy5.name })
        local card = Fk:cloneCard("heg_trueaim_another")
        room:getVirtCardId(card)
        room:showVirtualCard(card, player, nil, room.logic:getCurrentEvent().id + 1)
    end,
})

return policy5
